package org.tao.lightningmq.common.tcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @Author lht
 * @date 2025/1/7 - 15:05
 * @description:
 */
public class TcpMsgEncoder extends MessageToByteEncoder<TcpMsg> {

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, TcpMsg tcpMsg, ByteBuf byteBuf) throws Exception {
        byteBuf.writeShort(tcpMsg.getMagic());
        byteBuf.writeInt(tcpMsg.getCode());
        byteBuf.writeInt(tcpMsg.getLen());
        byteBuf.writeBytes(tcpMsg.getBody());
    }

}
